package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseDocument;
import com.ruoyi.base.service.IBaseDocumentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 型号Controller
 * 
 * @author yepanpan
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/base/document")
public class BaseDocumentController extends BaseController
{
    @Autowired
    private IBaseDocumentService baseDocumentService;

    /**
     * 查询型号列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseDocument baseDocument)
    {
        startPage();
        List<BaseDocument> list = baseDocumentService.selectBaseDocumentList(baseDocument);
        return getDataTable(list);
    }

    /**
     * 导出型号列表
     */
    @PreAuthorize("@ss.hasPermi('base:document:export')")
    @Log(title = "型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDocument baseDocument)
    {
        List<BaseDocument> list = baseDocumentService.selectBaseDocumentList(baseDocument);
        ExcelUtil<BaseDocument> util = new ExcelUtil<BaseDocument>(BaseDocument.class);
        util.exportExcel(response, list, "型号数据");
    }

    /**
     * 获取型号详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseDocumentService.selectBaseDocumentById(id));
    }

    /**
     * 新增型号
     */
    @PreAuthorize("@ss.hasPermi('base:document:add')")
    @Log(title = "型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseDocument baseDocument)
    {
        return toAjax(baseDocumentService.insertBaseDocument(baseDocument));
    }

    /**
     * 修改型号
     */
    @PreAuthorize("@ss.hasPermi('base:document:edit')")
    @Log(title = "型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseDocument baseDocument)
    {
        return toAjax(baseDocumentService.updateBaseDocument(baseDocument));
    }

    /**
     * 删除型号
     */
    @PreAuthorize("@ss.hasPermi('base:document:remove')")
    @Log(title = "型号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseDocumentService.deleteBaseDocumentByIds(ids));
    }
}
